<?php

use think\migration\Migrator;
use think\migration\db\Column;

class CreateShopOrder extends Migrator
{
    /**
     * Change Method.
     *
     * Write your reversible migrations using this method.
     *
     * More information on writing migrations is available here:
     * http://docs.phinx.org/en/latest/migrations.html#the-abstractmigration-class
     *
     * The following commands can be used in this method and Phinx will
     * automatically reverse them when rolling back:
     *
     *    createTable
     *    renameTable
     *    addColumn
     *    renameColumn
     *    addIndex
     *    addForeignKey
     *
     * Remember to call "create()" or "update()" and NOT "save()" when working
     * with the Table class.
     */
    public function change()
    {
        $table = $this->table('shop_order',['engine'=>'InnoDB'])->setComment('商城-订单');
        $table->addColumn(Column::integer('uid')->setDefault(0)->setComment('会员ID'));
        $table->addColumn(Column::integer('pt_id')->setDefault(0)->setComment('拼团id'));
        $table->addColumn(Column::tinyInteger('type')->setDefault(1)->setComment('订单类型(1普通订单,2换货订单,3秒杀订单，4拼团订单)'));
        $table->addColumn(Column::string('title')->setNullable()->setComment('订单标题'));
        $table->addColumn(Column::tinyInteger('express_type')->setDefault(1)->setComment('1快递，2自提'));
        $table->addColumn(Column::text('address_info')->setNullable()->setComment('发货信息'));
        $table->addColumn(Column::string('order_no',20)->setNullable()->setComment('订单号'));
        $table->addColumn(Column::decimal('freight_price',12,2)->setDefault(0)->setComment('快递费'));
        $table->addColumn(Column::decimal('goods_price',12,2)->setDefault(0)->setComment('商品总金额(不含快递费)'));
        $table->addColumn(Column::decimal('total_price',12,2)->setDefault(0)->setComment('真实支付金额(商品金额+快递金额)'));
        $table->addColumn(Column::decimal('pay_price',12,2)->setDefault(0)->setComment('实际支付金额'));
        $table->addColumn(Column::dateTime('pay_time')->setNullable()->setComment('支付时间'));
        $table->addColumn(Column::tinyInteger('is_remind')->setDefault(0)->setComment('是否已提醒发货：1已提醒，0未提醒'));
        $table->addColumn(Column::tinyInteger('is_pay')->setDefault(0)->setComment('订单支付状态(0.未支付,1.已支付)'));
        $table->addColumn(Column::tinyInteger('pay_type')->setDefault(1)->setComment('1微信，2线下支付'));
        $table->addColumn(Column::string('pay_no',100)->setNullable()->setComment('商户交易号'));
        $table->addColumn(Column::dateTime('delivery_time')->setNullable()->setComment('发货时间'));
        $table->addColumn(Column::dateTime('complete_time')->setNullable()->setComment('确认收货时间'));
        $table->addColumn(Column::tinyInteger('status')->setDefault(1)->setComment('订单状态(-1.无效,1.新订单,2.待发货,3.已发货,4.已收货,5.已完成,6.已退货及退款)'));
        $table->addColumn(Column::string('desc')->setNullable()->setComment('描述'));
        $table->addColumn(Column::tinyInteger('is_deleted')->setDefault(0)->setComment('删除(1:删除,0:未删)'));
        $table->addTimestamps('create_at');
        $table->create();
    }
}
